<?php

namespace app\admin\Controller;

use think\Controller;

class Dingding extends Controller
{
    public function index()
    {
        return $this->fetch();
    }

    public function ding()
    {
        if (request()->isAjax()) {
            $post = input('post.');
        }
    }
    public function user()
    {
        $list = db('user')
            ->paginate(1, false, ['query' => request()->param()]);
        $pag = $list->render();
        $this->assign('pag', $pag);
        $this->assign('list', $list);
        return $this->fetch();
    }
    public function vying()
    {
        return $this->fetch();
    }
    public function xiangmu()
    {
        $list = db('xiangmu')
            ->where('stauts', 0)
            ->paginate(10, false, ['query' => request()->param()]);
        $pag = $list->render();
        $this->assign('pag', $pag);
        $this->assign('list', $list);
        return $this->fetch();
    }
    public function tian()
    {
        $id = input('id');
        $list = db('xiangmu')->where('id', $id)->select();
        if ($list) {
            foreach ($list as &$y) {
                $y['total'] = json_decode($y['thumb']);
            }
        };
        $this->assign('list', $list);
        return $this->fetch();
    }
    public function list()
    {
        if (request()->isAjax()) {
            $post = input('post.');
            if (empty($post['thumb'])) {
                $this->error('请上传图片');
            } else {
                $in = db('xiangmu')->insert([
                    'name' => $post['name'],
                    'danwei' => $post['danwei'],
                    'touzi' => $post['touzi'],
                    'jihua' => $post['jihua'],
                    'wancheng' => $post['wancheng'],
                    'jianshe' => $post['jianshe'],
                    'gongzuo' => $post['gongzuo'],
                    'bang' => $post['bang'],
                    'wenti' => $post['wenti'],
                    'thumb' => $post['thumb']
                ]);
                if ($in) {
                    $this->success('添加成功', 'admin/dingding/xingmu');
                }
            }
        }
    }
    public function xiangqing()
    {

        return $this->fetch();
    }
    public function delete()
    {
        if (request()->isAjax()) {
            $id = input('id');
            $isok = db('xiangmu')->where('id', $id)->update([
                'stauts' => 1
            ]);
            $arr = [];
            if ($isok) {
                $arr['code'] = 1;
                $arr['msg'] = '删除成功';
            } else {
                $arr['code'] = 2;
            }
            return $arr;
        }
    }
    public function anzhi()
    {
        $list = db('jianshe')->paginate(10, false, ['query' => request()->param()]);
        $pag = $list->render();
        $this->assign('pag', $pag);
        $this->assign('list', $list);
        return $this->fetch();
    }
    public function sheshi()
    {
        return $this->fetch();
    }
}
